package com.CST.service.impl.cb;

import com.CST.common.api.Response;
import com.CST.entity.cb.AccvouchWorkload;
import com.CST.entity.cb.AccvouchWorkloadDTO;
import com.CST.mapper.ufdata.AccvouchMapper;
import com.CST.service.cb.IAccvouchWorkloadService;
import com.CST.util.ExcelTransfer;
import com.CST.util.PageHelperTool;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Service
public class AccvouchWorkloadServiceImpl extends ServiceImpl<AccvouchMapper, AccvouchWorkload> implements IAccvouchWorkloadService {


    
    @Autowired
    private AccvouchMapper accvouchMapper;

    @Autowired
    private ExcelTransfer<AccvouchWorkload> excelTransfer;


    @Override
    public Response getAccvouchWorkload(AccvouchWorkloadDTO entity) {
        List<AccvouchWorkload> list =accvouchMapper.getAccvouchWorkload(entity.getStartDate(), entity.getEndDate());
        return Response.success(PageHelperTool.excutePageInfo(list, entity.getPageIndex(), entity.getPageSize()));
    }

    @Override
    public void exportExcel(HttpServletResponse response, AccvouchWorkloadDTO dto) throws ClassNotFoundException {
        dto.setStartDate(dto.getStartDate().replace("-",""));
        dto.setEndDate(dto.getEndDate().replace("-",""));
        List<AccvouchWorkload> list =accvouchMapper.getAccvouchWorkload(dto.getStartDate(), dto.getEndDate());
        excelTransfer.exportExcel(response, list, "分录凭证", "sheet", this);
    }
}
